package com.hxk.jwt.service;

import com.hxk.jwt.entity.User;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserService {

    List<User> users = Arrays.asList(
            new User("1","zhangsan","123456"),
            new User("2","lisi","123456"),
            new User("3","wangwu","123456"),
            new User("4","zhuliu","123456")
    );

    public User findUserById(String userId) {
        return users.stream().filter(u->userId.equals(u.getId())).collect(Collectors.toList()).get(0);
    }

    public User findByUsername(User user) {
        List<User> users = this.users.stream().filter(u -> user.getUsername().equals(u.getUsername())).collect(Collectors.toList());
        return users.size() > 0 ? users.get(0) : null;
    }
}
